﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace UsefulTools
{
    public static class Config
    {
        // 默认当前路径下的Config.ini文件
        public static String configPath = "Config.ini";

        public static bool IsExist() { 
            return System.IO.File.Exists(configPath);
        }

        public static void Create() { 
            // 创建Config.ini文件,并写入默认配置:当前路径/Functions
            System.IO.File.Create(configPath).Close();
            System.IO.StreamWriter sw = new System.IO.StreamWriter(configPath, true);
            sw.WriteLine(System.AppDomain.CurrentDomain.BaseDirectory + "Functions");
            sw.Close();
        }

        public static void Delete() {
            // 删除Config.ini文件
            System.IO.File.Delete(configPath);
        }

        public static String Read() {
            // 读取Config.ini文件
            System.IO.StreamReader sr = new System.IO.StreamReader(configPath);
            string line;
            line = sr.ReadLine();
            sr.Close();
            if (line!= null) return line;
            return "";
        }

        public static void Write(String path) {
            // 写入Config.ini文件
            System.IO.StreamWriter sw = new System.IO.StreamWriter(configPath, false);
            sw.WriteLine(path);
            sw.Close();
        }
    }
}
